<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Context Free LALR1 compiler: src/contextFree/scanner/LR0.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Context Free LALR1 compiler
   &#160;<span id="projectnumber">1.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_l_r0_8java.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">src/contextFree/scanner/LR0.java</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>contextFree.scanner;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="keyword">import</span> java.util.Arrays;
<a name="l00005"></a>00005 <span class="keyword">import</span> java.util.Iterator;
<a name="l00006"></a>00006 <span class="keyword">import</span> java.util.LinkedList;
<a name="l00007"></a>00007 <span class="keyword">import</span> java.util.List;
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">import</span> contextFree.grammar.IGrammar;
<a name="l00010"></a>00010 <span class="keyword">import</span> contextFree.grammar.Production;
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 
<a name="l00013"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html">00013</a> <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">class </span><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html">LR0</a> <span class="keyword">implements</span> <a class="code" href="interfacecontext_free_1_1scanner_1_1_i_scanner.html">IScanner</a>{
<a name="l00014"></a>00014 
<a name="l00015"></a>00015         <span class="keyword">protected</span> <a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html" title="Grammar Interface.">IGrammar</a> grammatica;
<a name="l00016"></a>00016         
<a name="l00017"></a>00017         <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keywordtype">void</span> setGrammar(<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html" title="Grammar Interface.">IGrammar</a> gram);
<a name="l00018"></a>00018         <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keywordtype">int</span> init() <span class="keywordflow">throws</span> Exception;    
<a name="l00019"></a>00019 
<a name="l00027"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a313dfc00f370a910932b02034e26fb8c">00027</a>         <span class="keyword">public</span> List&lt;IndexedProduction&gt; <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a313dfc00f370a910932b02034e26fb8c" title="*I passed a list of production that form the kernel of a state, return closing it">chiusura</a> (List&lt;IndexedProduction&gt; i){
<a name="l00028"></a>00028                 <span class="keywordtype">boolean</span> flag =<span class="keyword">true</span>;
<a name="l00029"></a>00029                 <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a> =<span class="keyword">true</span>;
<a name="l00030"></a>00030                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> item ;
<a name="l00031"></a>00031                 <a class="code" href="classcontext_free_1_1grammar_1_1_production.html">Production</a> corrente;
<a name="l00032"></a>00032                 String x;
<a name="l00033"></a>00033                 Object[] ob;
<a name="l00034"></a>00034                 String[] right;
<a name="l00035"></a>00035 
<a name="l00036"></a>00036                 <span class="comment">//Copio il kernel item I in una List&lt;IndexedProduction&gt; j cosi&#39; avro&#39; sia i Kernel che i relativi Item che formano la chiusura</span>
<a name="l00037"></a>00037                 List&lt;IndexedProduction&gt; j = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00038"></a>00038                 j.addAll(i);
<a name="l00039"></a>00039                 <span class="comment">//fino a quando  vengono aggiunti nuovi item a J</span>
<a name="l00040"></a>00040                 <span class="keywordflow">while</span> (flag) {
<a name="l00041"></a>00041                         flag=<span class="keyword">false</span>;
<a name="l00042"></a>00042                         Iterator &lt;IndexedProduction&gt; iter = j.iterator();
<a name="l00043"></a>00043                         <span class="keywordflow">while</span>(iter.hasNext()){
<a name="l00044"></a>00044                                 <span class="comment">//per ogni Item appartenente a j</span>
<a name="l00045"></a>00045                                 item = iter.next();
<a name="l00046"></a>00046                                 System.out.println(item);
<a name="l00047"></a>00047                                 ob = item.getRightSimbols().toArray();
<a name="l00048"></a>00048                                 System.out.println(item.getRightSimbols());
<a name="l00049"></a>00049                                 right = Arrays.copyOf(ob,ob.length,String[].class);
<a name="l00050"></a>00050                                 <span class="comment">//Se il puntino si trova nell&#39;ultima posizione, ossia l&#39;indice di posizione � maggiore o uguale </span>
<a name="l00051"></a>00051                                 <span class="comment">//della lunghezza del Rightlist</span>
<a name="l00052"></a>00052                                 <span class="keywordflow">if</span>(item.getCurrentCharIndex() &gt;= item.getRightSimbols().size()){
<a name="l00053"></a>00053                                         <span class="comment">//esci dal while xk� ci troviamo nel caso chiusura e quindi non possiamo </span>
<a name="l00054"></a>00054                                         <span class="comment">//trovare alcuna produzione che ha nella parte sinistra l&#39;elemento che segue il punto</span>
<a name="l00055"></a>00055                                         <span class="keywordflow">break</span>;
<a name="l00056"></a>00056                                 }
<a name="l00057"></a>00057                                 <span class="comment">//prendo il simbolo che segue il puntino nella produzione A:= a.Bc</span>
<a name="l00058"></a>00058                                 x =(String) right[item.getCurrentCharIndex()];
<a name="l00059"></a>00059                                 Iterator&lt;Production&gt; prod = grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a629ab4dc36a869b93fa239a3fee760f9" title="Get production list.">getP</a>().iterator();
<a name="l00060"></a>00060                                 <span class="comment">//per ogni produzione della grammatica </span>
<a name="l00061"></a>00061                                 <span class="keywordflow">while</span> (prod.hasNext()){
<a name="l00062"></a>00062                                         corrente=prod.next();
<a name="l00063"></a>00063                                         
<a name="l00064"></a>00064                                         <span class="comment">//se il simbolo alla destra del punto e&#39; uguale alla Parte sinistra della produzione B::= z</span>
<a name="l00065"></a>00065                                         <span class="keywordflow">if</span>(x.equals(corrente.getLeft())){
<a name="l00066"></a>00066                                                 <span class="comment">//se la produzione nn e&#39; gi presente in J</span>
<a name="l00067"></a>00067                                                 uguale =<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a43275125600a950a4a1f78ce565eac5f" title="checks if a production is already in a list of productions.">prodPresente</a>(j, corrente);
<a name="l00068"></a>00068                                                 <span class="keywordflow">if</span>(!uguale){
<a name="l00069"></a>00069                                                         <span class="comment">//aggiungo la produzione mettendo il punto come primo elemnto B::=.Z</span>
<a name="l00070"></a>00070                                                         j.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>(corrente));
<a name="l00071"></a>00071                                                         flag=<span class="keyword">true</span>;
<a name="l00072"></a>00072                                                 }
<a name="l00073"></a>00073                                         }
<a name="l00074"></a>00074                                 }
<a name="l00075"></a>00075                                 <span class="comment">//se ho aggiunto nuove produzioni devo uscire dal while(iter.hasNext()) e ricreare l&#39;iteratore sulla nuova Lista creata</span>
<a name="l00076"></a>00076                                 <span class="keywordflow">if</span>(flag)
<a name="l00077"></a>00077                                         <span class="keywordflow">break</span>;
<a name="l00078"></a>00078                         }
<a name="l00079"></a>00079                 }
<a name="l00080"></a>00080                 <span class="comment">//ritorna una lista chiusura con il kernel che la genera</span>
<a name="l00081"></a>00081                 <span class="keywordflow">return</span> j;
<a name="l00082"></a>00082         }
<a name="l00083"></a>00083         
<a name="l00084"></a>00084         
<a name="l00092"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a087486ba03c2fb5ab400e425e7b54bbc">00092</a>         <span class="keyword">public</span> List&lt;IndexedProduction&gt; <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a087486ba03c2fb5ab400e425e7b54bbc" title="Passed a state and the symbol that follows the point, returns the kernel of the new state with the re...">GoTo</a>(List&lt;IndexedProduction&gt; i, String X){
<a name="l00093"></a>00093                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> item;
<a name="l00094"></a>00094                 Object[] ob;
<a name="l00095"></a>00095                 String [] right;
<a name="l00096"></a>00096                 List&lt;IndexedProduction&gt; j = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00097"></a>00097                 Iterator &lt;IndexedProduction&gt; iter = i.iterator();
<a name="l00098"></a>00098                 <span class="comment">//Per ogni produzione contenuta in I</span>
<a name="l00099"></a>00099                 <span class="keywordflow">while</span> (iter.hasNext()){
<a name="l00100"></a>00100                         item = iter.next();
<a name="l00101"></a>00101                         ob= item.getRightSimbols().toArray();
<a name="l00102"></a>00102                         right = Arrays.copyOf(ob ,ob.length ,String[].class);
<a name="l00103"></a>00103                         <span class="comment">//se il puntino non si trova nell&#39;ultima posizione</span>
<a name="l00104"></a>00104                         <span class="keywordflow">if</span>(!(item.getCurrentCharIndex() &gt;= item.getRightSimbols().size()))
<a name="l00105"></a>00105                                 <span class="comment">//controlliamo se il carattere che segue il punto e&#39; lo stesso di A::= a.Xc</span>
<a name="l00106"></a>00106                                 <span class="keywordflow">if</span>(right[item.getCurrentCharIndex()].equals(X))
<a name="l00107"></a>00107                                         <span class="comment">//quindi aggiungiamo la produzione a J spostando il punto al carattere succesivo</span>
<a name="l00108"></a>00108                                         j.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>(item.getCurrentCharIndex()+1, item));
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110                 <span class="comment">//ritorna il nuovo kernel con la relativa chiusura</span>
<a name="l00111"></a>00111                 <span class="keywordflow">return</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a313dfc00f370a910932b02034e26fb8c" title="*I passed a list of production that form the kernel of a state, return closing it">chiusura</a>(j);
<a name="l00112"></a>00112         }
<a name="l00113"></a>00113         
<a name="l00121"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a5c7d77fe2a994398ef6312251e2f6109">00121</a>         <span class="keyword">public</span> List&lt;State&gt; <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a5c7d77fe2a994398ef6312251e2f6109" title="given a grammar G we calculate the associated grammar augmented by adding the production S &#39;:: =...">Item</a>(){
<a name="l00122"></a>00122                 <span class="keywordtype">boolean</span> flag = <span class="keyword">true</span>;
<a name="l00123"></a>00123                 <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> stato;
<a name="l00124"></a>00124                 Object[] ob;
<a name="l00125"></a>00125                 String[] x;
<a name="l00126"></a>00126                 List&lt;IndexedProduction&gt;chiusraX = <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00127"></a>00127                 List&lt;State&gt; automa = <span class="keyword">new</span> LinkedList&lt;State&gt;();
<a name="l00128"></a>00128                 List&lt;IndexedProduction&gt; aumentata= <span class="keyword">new</span> LinkedList&lt;IndexedProduction&gt;();
<a name="l00129"></a>00129                 <span class="comment">//creiamo una produzione S&#39;::= S che fa diventare la nostra grammatica aumentata</span>
<a name="l00130"></a>00130                 <a class="code" href="classcontext_free_1_1grammar_1_1_production.html">Production</a> p = <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1grammar_1_1_production.html">Production</a>(<span class="stringliteral">&quot;S&#39;&quot;</span>, grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#aceb36e584d26bd39a0f5186742cc9b5b" title="Get the axioms.">getS</a>());
<a name="l00131"></a>00131                 <span class="comment">//dopo di che inseriamo il tutto in un List&lt;IndexedProdaction&gt; mettendo il punto al primo posto nella produzione S&#39;::=.S</span>
<a name="l00132"></a>00132                 aumentata.add( <span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a>(0, p,<span class="stringliteral">&quot;$&quot;</span>));
<a name="l00133"></a>00133                 <span class="comment">//per poterlo inserire nell&#39;automa al primo posto come Stat[0]</span>
<a name="l00134"></a>00134                 automa.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a>(0, <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a313dfc00f370a910932b02034e26fb8c" title="*I passed a list of production that form the kernel of a state, return closing it">chiusura</a>(aumentata)));
<a name="l00135"></a>00135                 <span class="comment">//fino a quando vengono aggiunti nuovi insiemi di item ad AUTOMA</span>
<a name="l00136"></a>00136                 <span class="keywordflow">while</span>(flag){
<a name="l00137"></a>00137                         flag=<span class="keyword">false</span>;
<a name="l00138"></a>00138                         Iterator &lt;State&gt; iter = automa.iterator();
<a name="l00139"></a>00139                         <span class="comment">//per ogni insieme di item(o stato) nell&#39;Automa</span>
<a name="l00140"></a>00140                         <span class="keywordflow">while</span>(iter.hasNext()){
<a name="l00141"></a>00141                                 stato =iter.next();
<a name="l00142"></a>00142                                 <span class="comment">//recupero la Lsit&lt;indexedProduction&gt;contenente tutte le produzioni</span>
<a name="l00143"></a>00143                                 List&lt;IndexedProduction&gt;Items = stato.getItems();
<a name="l00144"></a>00144                                 <span class="comment">//per ogni  NON Terminale della grammatica</span>
<a name="l00145"></a>00145                                 ob= grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().toArray();
<a name="l00146"></a>00146                                 x = Arrays.copyOf(ob,ob.length,String[].class);
<a name="l00147"></a>00147                                         <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a4b1bc2134e63051dc37e693294aaeec6" title="Get non-terminal symbols list.">getV</a>().size();i++){
<a name="l00148"></a>00148                                                 <span class="comment">//faccio il GoTo dello stato </span>
<a name="l00149"></a>00149                                                 chiusraX =<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a087486ba03c2fb5ab400e425e7b54bbc" title="Passed a state and the symbol that follows the point, returns the kernel of the new state with the re...">GoTo</a>(Items, x[i]);
<a name="l00150"></a>00150                                                 <span class="comment">//TODO se si crea il nuovo stato vado a inserire lo SHIFT nella tabella degli GOTO Inquanto generato da un Terminale</span>
<a name="l00151"></a>00151                                                 <span class="comment">//se ChiusuraX non e&#39; vuoto AND non e&#39; contenuta nell&#39;automa</span>
<a name="l00152"></a>00152                                                 <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>=<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>(automa,chiusraX);
<a name="l00153"></a>00153                                                 <span class="keywordflow">if</span>(!chiusraX.isEmpty())
<a name="l00154"></a>00154                                                         <span class="keywordflow">if</span>(uguale==-1){
<a name="l00155"></a>00155                                                                 <span class="comment">//allora lo aggiungo</span>
<a name="l00156"></a>00156                                                                 automa.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a>(automa.size(),chiusraX));
<a name="l00157"></a>00157                                                                 <span class="comment">//e setto nella lista degli shift dello stato di origine, lo spostamento per il simbolo x[i] al nuovo stato</span>
<a name="l00158"></a>00158                                                                 stato.getShift().put(x[i],automa.size()-1);
<a name="l00159"></a>00159                                                                 flag=<span class="keyword">true</span>;
<a name="l00160"></a>00160                                                         }<span class="keywordflow">else</span>{
<a name="l00161"></a>00161                                                                 <span class="comment">//se chiusurax gi� esiste aggiungo alla lista degli shift dello stato di origine, lo spostamento per il simbolo x[i] allo stato uguale</span>
<a name="l00162"></a>00162                                                                 stato.getShift().put(x[i], uguale);
<a name="l00163"></a>00163                                                         }
<a name="l00164"></a>00164                                         }
<a name="l00165"></a>00165                                         <span class="comment">//ora si deve fare la stessa cosa per i non terminali</span>
<a name="l00166"></a>00166                                         ob = grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().toArray();
<a name="l00167"></a>00167                                         x = Arrays.copyOf(ob,ob.length,String[].class);
<a name="l00168"></a>00168                                         <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;grammatica.<a class="code" href="interfacecontext_free_1_1grammar_1_1_i_grammar.html#a996f5e0bed5a6ac469b764f56d420fb1" title="Get terminal symbols list.">getT</a>().size();i++){
<a name="l00169"></a>00169                                                 <span class="comment">//faccio il GoTo dello stato </span>
<a name="l00170"></a>00170                                                 chiusraX =<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a087486ba03c2fb5ab400e425e7b54bbc" title="Passed a state and the symbol that follows the point, returns the kernel of the new state with the re...">GoTo</a>(Items, x[i]);
<a name="l00171"></a>00171                                                 <span class="comment">//TODO se si crea il nuovo stato vado a inserire lo SHIFT  o REDUCE nella tabella dei ACTION Inquanto generato da un NON Terminale</span>
<a name="l00172"></a>00172                                                 <span class="comment">//se ChiusuraX non e&#39; vuoto AND non e&#39; contenuta nell&#39;automa</span>
<a name="l00173"></a>00173                                                 <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>=<a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>(automa,chiusraX);
<a name="l00174"></a>00174                                                 <span class="keywordflow">if</span>(!chiusraX.isEmpty())
<a name="l00175"></a>00175                                                         <span class="keywordflow">if</span>(uguale==-1){
<a name="l00176"></a>00176                                                                 <span class="comment">//allora lo aggiungo</span>
<a name="l00177"></a>00177                                                                 automa.add(<span class="keyword">new</span> <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a>(automa.size(),chiusraX));
<a name="l00178"></a>00178                                                                 <span class="comment">//e setto nella lista degli shift dello stato di origine, lo spostamento per il simbolo x[i] al nuovo stato  </span>
<a name="l00179"></a>00179                                                                 stato.getShift().put(x[i],automa.size()-1);
<a name="l00180"></a>00180                                                                 flag=<span class="keyword">true</span>;
<a name="l00181"></a>00181                                                         }<span class="keywordflow">else</span>{
<a name="l00182"></a>00182                                                                 <span class="comment">//se chiusurax gi� esiste aggiungo alla lista degli shift dello stato di origine, lo spostamento per il simbolo x[i] allo stato uguale</span>
<a name="l00183"></a>00183                                                                 stato.getShift().put(x[i], uguale);
<a name="l00184"></a>00184                                                         }
<a name="l00185"></a>00185                                         }
<a name="l00186"></a>00186                                         <span class="comment">//se ho aggiunto nuovi stati all&#39;automa devo uscire dal while(iter.hasNext()) e ricreare l&#39;iteratore sulla nuova struttura</span>
<a name="l00187"></a>00187                                         <span class="keywordflow">if</span>(flag)
<a name="l00188"></a>00188                                                 <span class="keywordflow">break</span>;
<a name="l00189"></a>00189                                 }
<a name="l00190"></a>00190                 }
<a name="l00191"></a>00191                 <span class="keywordflow">return</span> automa;
<a name="l00192"></a>00192         }
<a name="l00193"></a>00193         
<a name="l00201"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782">00201</a>         <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>(List&lt;State&gt; automa, List&lt;IndexedProduction&gt; stato){
<a name="l00202"></a>00202                 <a class="code" href="classcontext_free_1_1scanner_1_1_state.html">State</a> it;
<a name="l00203"></a>00203                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> prod ;
<a name="l00204"></a>00204                 <span class="keywordtype">int</span> leng=0;
<a name="l00205"></a>00205                 <span class="keywordtype">int</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a> = -1;
<a name="l00206"></a>00206                 <span class="keywordtype">int</span> proUguali = 0;      <span class="comment">//questa variabile ci servir� per controllare che tutte le produzioni siano uguali</span>
<a name="l00207"></a>00207         
<a name="l00208"></a>00208                 Iterator&lt;State&gt; iter = automa.iterator();
<a name="l00209"></a>00209                 <span class="comment">//per ogni stato dell&#39;automa</span>
<a name="l00210"></a>00210                 <span class="keywordflow">while</span> (iter.hasNext()){
<a name="l00211"></a>00211                         it= iter.next();
<a name="l00212"></a>00212                         <span class="comment">//prendiamo la lista delle produzioni dello stato</span>
<a name="l00213"></a>00213                         Iterator&lt;IndexedProduction&gt; stato1 = it.getItems().iterator();
<a name="l00214"></a>00214                         <span class="comment">//questa variabile contera&#39; quante produzioni sono uguali a quello dello stato che stiamo controllando </span>
<a name="l00215"></a>00215                         proUguali = 0;
<a name="l00216"></a>00216                         leng=0;
<a name="l00217"></a>00217                         <span class="comment">//per ogni produzione contenuta nell&#39;iteratore</span>
<a name="l00218"></a>00218                         <span class="keywordflow">while</span>(stato1.hasNext()){
<a name="l00219"></a>00219                                 prod = stato1.next();
<a name="l00220"></a>00220                                 leng++;
<a name="l00221"></a>00221                                 <span class="comment">//controllo se la produzione dello stato1 � presente nello stato che stiamo controllando, in caso incrementa il contatore</span>
<a name="l00222"></a>00222                                 <span class="keywordflow">for</span>(<a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> prodStato : stato)
<a name="l00223"></a>00223                                         <span class="comment">//TODO:</span>
<a name="l00224"></a>00224                                 <span class="keywordflow">if</span> (prodStato.getLeft().equalsIgnoreCase(prod.getLeft())
<a name="l00225"></a>00225                                                 &amp;
<a name="l00226"></a>00226                                         prodStato.getRight().equalsIgnoreCase(prod.getRight())
<a name="l00227"></a>00227                                                 &amp;
<a name="l00228"></a>00228                                                 prodStato.getCurrentCharIndex()==prod.getCurrentCharIndex())
<a name="l00229"></a>00229                                         proUguali++;
<a name="l00230"></a>00230                         }
<a name="l00231"></a>00231                         <span class="comment">//se il numero di produzioni uguali � uguale alla dimensione dello stato vuol dire che</span>
<a name="l00232"></a>00232                         <span class="keywordflow">if</span> (proUguali == stato.size()
<a name="l00233"></a>00233                                                 &amp;
<a name="l00234"></a>00234                                 leng==proUguali){ 
<a name="l00235"></a>00235                                 <span class="comment">//sono tutti uguali e quindi </span>
<a name="l00236"></a>00236                                 uguale = it.getIndex();
<a name="l00237"></a>00237                                 <span class="keywordflow">break</span>;
<a name="l00238"></a>00238                         }
<a name="l00239"></a>00239                         
<a name="l00240"></a>00240                 } 
<a name="l00241"></a>00241                 <span class="keywordflow">return</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>;  
<a name="l00242"></a>00242         }
<a name="l00243"></a>00243         
<a name="l00251"></a><a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a43275125600a950a4a1f78ce565eac5f">00251</a>         <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#a43275125600a950a4a1f78ce565eac5f" title="checks if a production is already in a list of productions.">prodPresente</a>(List&lt;IndexedProduction&gt;j,<a class="code" href="classcontext_free_1_1grammar_1_1_production.html">Production</a> corrente){
<a name="l00252"></a>00252                 <span class="comment">//uso questa variabile per vedere se � gi� presente in j la setto di default a false, e poi la cambio se ne trova 2  uguali</span>
<a name="l00253"></a>00253                 <span class="keywordtype">boolean</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>=<span class="keyword">false</span>;
<a name="l00254"></a>00254                 <a class="code" href="classcontext_free_1_1scanner_1_1_indexed_production.html">IndexedProduction</a> item1;
<a name="l00255"></a>00255                 
<a name="l00256"></a>00256                 Iterator &lt;IndexedProduction&gt; iter1 = j.iterator();
<a name="l00257"></a>00257                 <span class="keywordflow">while</span>(iter1.hasNext()){
<a name="l00258"></a>00258                         <span class="comment">//per ogni Item appartenente a j</span>
<a name="l00259"></a>00259                         item1 = iter1.next();
<a name="l00260"></a>00260                         <span class="comment">//controllo sia se la parte destra che la parte sinistra sono gi� presenti</span>
<a name="l00261"></a>00261                         <span class="keywordflow">if</span> (item1.getRight().equals(corrente.getRight()) 
<a name="l00262"></a>00262                                                                 &amp;
<a name="l00263"></a>00263                                 item1.getLeft().equals(corrente.getLeft())
<a name="l00264"></a>00264                                 &amp;
<a name="l00265"></a>00265                                 item1.getCurrentCharIndex()==0)
<a name="l00266"></a>00266                                 {
<a name="l00267"></a>00267                                 <span class="comment">//setto la variabile booleana a TRUE per segnalare che sono uguali</span>
<a name="l00268"></a>00268                                 uguale =<span class="keyword">true</span>;
<a name="l00269"></a>00269                                 <span class="comment">//esco dal ciclo xke&#39; gia&#39; ho trovato la corrispondenza</span>
<a name="l00270"></a>00270                                 <span class="keywordflow">break</span>;
<a name="l00271"></a>00271                                 }
<a name="l00272"></a>00272                         }
<a name="l00273"></a>00273                 <span class="keywordflow">return</span> <a class="code" href="classcontext_free_1_1scanner_1_1_l_r0.html#ace66d28273502a9daf8e4550f48b5782" title="checks if a state is present in an automaton">uguale</a>;
<a name="l00274"></a>00274         }       
<a name="l00275"></a>00275 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>LR0.java</b>      </li>

    <li class="footer">Generated on Fri Mar 30 2012 21:26:23 for Context Free LALR1 compiler by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
